package com.example.controller;

import com.example.entity.Advice;
import com.example.entity.Dormitory;
import com.example.entity.Floor;
import com.example.entity.Stayinfo;
import com.example.mapper.AdviceMapper;
import com.example.service.AdviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/Advice")
public class AdviceConstoller {
    @Autowired
    private AdviceMapper adviceMapper;
    @Autowired
    private AdviceService adviceService;

    @GetMapping
    public List<Advice> index() {
        List<Advice> all = adviceMapper.finAll();
        return all;
    }
    @PostMapping
    public Map<String, Object> save(@RequestBody Advice advice){
        return adviceService.saveAdvice(advice);
    }
    @DeleteMapping("/delete")
    public Map<String, Object> deleteByStuNum(@RequestParam Integer advice_id) {
        return adviceService.deleteByAdviceId(advice_id);
    }

    @GetMapping("/page")
    public Map<String, Object> findDormitoryPage(@RequestParam Integer pageNum,
                                                 @RequestParam Integer pageSize,
                                                 @RequestParam String stu_num) {
        pageNum = (pageNum - 1) * pageSize;
        List<Advice> data = adviceMapper.selectPage(pageNum, pageSize, stu_num);
        Integer total = adviceMapper.selectTotal(stu_num);
        Map<String, Object> res = new HashMap<>();
        res.put("data", data);
        res.put("total", total);
        return res;
    }


}
